﻿using System.Collections;
using System.Data;
using OA.Manager;
using OA.Model;

namespace OA.Bll.Authority
{
    public class ModulesPresenter : BasePresenter<ModulesInfo>
    {

        readonly ModulesManager _dal;

        public ModulesPresenter()
        {
            _dal = new ModulesManager();
        }
        /// <summary>
        /// 判断模块分类是否存在
        /// </summary>
        /// <param name="moduleTypeName">模块分类名称</param>
        /// <returns></returns>
        public bool ModuleTypeExists(string moduleTypeName)
        {

            return _dal.ModuleTypeExists(moduleTypeName);
        }

        /// <summary>
        /// 增加一个模块分类
        /// </summary>
        /// <param name="model">模块分类实体类</param>
        /// <returns></returns>
        public int CreateModuleType(ModuleTypeInfo model)
        {
            return !ModuleTypeExists(model.ModuleTypeName) ? _dal.CreateModuleType(model) : 2;
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="model">模块分类实体类</param>
        /// <returns></returns>
        public bool UpdateModuleType(ModuleTypeInfo model)
        {
            return _dal.UpdateModuleType(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        /// <param name="moduleTypeID">模块分类ID</param>
        /// <returns></returns>
        public int DeleteModuleType(int moduleTypeID)
        {
            return _dal.DeleteModuleType(moduleTypeID);
        }

        /// <summary>
        /// 得到一个模块分类实体
        /// </summary>
        /// <param name="moduleTypeID">模块分类ID</param>
        /// <returns></returns>
        public ModuleTypeInfo GetModuleTypeModel(int moduleTypeID)
        {
            return _dal.GetModuleTypeModel(moduleTypeID);
        }

        /// <summary>
        /// 获得模块分类数据列表
        /// </summary>
        /// <param>Where条件 <name>strWhere</name> </param>
        /// <param name="strWhere"> </param>
        /// <returns></returns>
        public DataSet GetModuleTypeList(string strWhere)
        {
            return _dal.GetModuleTypeList(strWhere);
        }

        #region 模块操作

        /// <summary>
        /// 判断模块是否存在
        /// </summary>
        /// <returns></returns>
        public bool ModuleExists(string moduleTag)
        {
            return _dal.ModuleExists(moduleTag);
        }

        /// <summary>
        /// 更新时判断模块是否存在
        /// </summary>
        /// <returns></returns>
        public bool UpdateExists(string moduleTag)
        {
            return _dal.UpdateExists(moduleTag);
        }

        /// <summary>
        /// 增加一个模块
        /// </summary>
        /// <param name="model">模块实体类</param>
        /// <returns></returns>
        public int CreateModule(ModulesInfo model)
        {
            if (!ModuleExists(model.ModuleTag))
            {
                return _dal.CreateModule(model);
            }
            else
                return 2;
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="model">模块实体类</param>
        /// <returns></returns>
        public int UpdateModule(ModulesInfo model)
        {
            return UpdateExists(model.ModuleTag) ? _dal.UpdateModule(model) : 2;
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        /// <param name="moduleID">模块ID</param>
        /// <returns></returns>
        public bool DeleteModule(int moduleID)
        {
            return _dal.DeleteModule(moduleID);
        }

        /// <summary>
        /// 得到一个模块实体
        /// </summary>
        /// <param name="moduleID">模块ID</param>
        /// <returns></returns>
        public ModulesInfo GetModuleModel(int moduleID)
        {
            return _dal.GetModuleModel(moduleID);
        }

        /// <summary>
        /// 获得模块数据列表
        /// </summary>
        /// <param>Where条件 <name>strWhere</name> </param>
        /// <param name="strWhere"> </param>
        /// <returns></returns>
        public DataSet GetModuleList(string strWhere)
        {
            return _dal.GetModuleList(strWhere);
        }

        /// <summary>
        /// 获得模块数据列表
        /// </summary>
        /// <param name="strWhere">Where条件</param>
        /// <returns></returns>
        public DataSet GetModuleList2(string strWhere)
        {
            return _dal.GetModuleList2(strWhere);
        }

        /// <summary>
        /// 获取模块ID
        /// </summary>
        /// <param name="moduleTag">模块标识</param>
        /// <returns></returns>
        public int GetModuleID(string moduleTag)
        {
            return _dal.GetModuleID(moduleTag);
        }

        /// <summary>
        /// 模块是否关闭
        /// </summary>
        /// <param name="moduleTag">模块标识</param>
        /// <returns></returns>
        public bool IsModule(string moduleTag)
        {
            return _dal.IsModule(moduleTag);
        }

        #endregion

        #region 模块授权

        /// <summary>
        /// 增加模块权限
        /// </summary>
        /// <param name="list">权限列表</param>
        /// <returns></returns>
        public bool CreateAuthorityList(ArrayList list)
        {
            return _dal.CreateAuthorityList(list);
        }

        /// <summary>
        /// 更新模块权限
        /// </summary>
        public bool UpdateAuthorityList(ArrayList list)
        {
            return _dal.UpdateAuthorityList(list);
        }

        /// <summary>
        /// 删除指定模块的权限列表
        /// </summary>
        /// <param name="moduleID">模块ID</param>
        /// <returns></returns>
        public bool DeleteAuthority(int moduleID)
        {
            return _dal.DeleteAuthority(moduleID);
        }

        /// <summary>
        /// 获得指定模块的权限列表
        /// </summary>
        /// <param name="moduleID">模块ID</param>
        /// <returns></returns>
        public DataSet GetAuthorityList(int moduleID)
        {
            return _dal.GetAuthorityList(moduleID);
        }

        /// <summary>
        /// 获得指定模块的权限列表
        /// </summary>
        /// <param name="moduleID">模块ID</param>
        /// <returns></returns>
        public DataSet GetAuthorityNameList(int moduleID)
        {
            return _dal.GetAuthorityNameList(moduleID);
        }

        #endregion
    }
}
